package pub.gll.onepeas.todo.hotfix

import android.Manifest
import android.app.Activity
import android.content.pm.PackageManager
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCompositionContext
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.core.app.ActivityCompat
import pub.gll.onepeas.libbase.Test
import pub.gll.onepeas.libbase.arouter.Launch
import pub.gll.onepeas.todo.R

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MainCompose(this)
        }

        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {
            if (ActivityCompat.checkSelfPermission(
                    this,
                    Manifest.permission.READ_EXTERNAL_STORAGE
                ) != PackageManager.PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(
                    this,
                    arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE),
                    1
                )
            }
        }
    }

    @Composable
    fun MainCompose(activity: Activity) {
        val scrollState = rememberScrollState()
        val context = LocalContext.current
        Column(modifier = Modifier.verticalScroll(scrollState)) {
            Button(onClick = {
                // 弹出一个Toast，显示 ToBeFixed 这个类返回的字符串
                Toast.makeText(context, ToBeFixed.get(), Toast.LENGTH_LONG).show()
            }) {
                Text(text = "CarComposeActivity")
            }
            Button(onClick = {
                Launch.customView()
            }) {
                Text(text = "CustomViewAct")
            }
            Button(onClick = {
                Launch.comicMain()
            }) {
                Text(text = "ComicMainAct")
            }
            Button(onClick = {
                Launch.webView(Test.TEST_VIP_VIDEO)
            }) {
                Text(text = "WebActivity")
            }
            Button(onClick = {
                Launch.videoPlay("http://106.54.112.102/live/livestream.flv")
            }) {
                Text(text = "PlayActivity")
            }
            Button(onClick = {
                Launch.videoList()
            }) {
                Text(text = "VideoAct")
            }
            Button(onClick = {
                Launch.downloadList()
            }) {
                Text(text = "DownloadListActivity")
            }
            Button(onClick = {
                Launch.esp8266()
            }) {
                Text(text = "ESP_8266")
            }

        }
    }
}